package com.ljy.my_study.spring.tiny.study9.aop;

import java.lang.reflect.Method;
import java.util.HashSet;
import java.util.Set;

import org.aspectj.lang.reflect.PointcutExpression;
import org.aspectj.weaver.tools.PointcutParser;
import org.aspectj.weaver.tools.PointcutPrimitive;

public class AspectJExpressPointcut implements Pointcut,ClassFilter,MethodMatcher{

	private PointcutParser parser;
	private String expression;
	private PointcutExpression pointcutExpression;

	private static final Set<PointcutPrimitive> DEFAULT_SUPPORTED_PRIMITIVES=new HashSet<>();
	
	static {
	/*
	 *	疑问：为什么不在构造器上将这些内容设置上？
	 *  个人观点：DEFAULT_SUPPORTED_PRIMITIVES属性不属于对象，属于类的，所以在static上设置，不在构造器上设置
	 */
		DEFAULT_SUPPORTED_PRIMITIVES.add(PointcutPrimitive.EXECUTION);
		DEFAULT_SUPPORTED_PRIMITIVES.add(PointcutPrimitive.ARGS);
		DEFAULT_SUPPORTED_PRIMITIVES.add(PointcutPrimitive.REFERENCE);
		DEFAULT_SUPPORTED_PRIMITIVES.add(PointcutPrimitive.THIS);
		DEFAULT_SUPPORTED_PRIMITIVES.add(PointcutPrimitive.TARGET);
		DEFAULT_SUPPORTED_PRIMITIVES.add(PointcutPrimitive.WITHIN);
		DEFAULT_SUPPORTED_PRIMITIVES.add(PointcutPrimitive.AT_ANNOTATION);
		DEFAULT_SUPPORTED_PRIMITIVES.add(PointcutPrimitive.AT_WITHIN);
		DEFAULT_SUPPORTED_PRIMITIVES.add(PointcutPrimitive.AT_ARGS);
		DEFAULT_SUPPORTED_PRIMITIVES.add(PointcutPrimitive.AT_TARGET);
	}

	public AspectJExpressPointcut() {
		this(DEFAULT_SUPPORTED_PRIMITIVES);
	}
	
	public AspectJExpressPointcut(Set<PointcutPrimitive> pointcutPrimitives) {
		parser=
			PointcutParser
				.getPointcutParserSupportingSpecifiedPrimitivesAndUsingContextClassloaderForResolution(
				pointcutPrimitives);
	}
	
	//使用方法设置而不是用构造器设置原因是可以不断设置值，产生不同结果；通过构造器设置则是一经对象创建则不能再设置
	public void setExpression() {
		
	}
	
	@Override
	public boolean matches(Class targetClass) {
		return false;
	}
	
	@Override
	public boolean matches(Method method, Class targetClass) {
		return false;
	}

	@Override
	public ClassFilter getClassFilter() {
		return this;
	}

	@Override
	public MethodMatcher getMethodMatcher() {
		return this;
	}

}
